import 'dart:async';

import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../state/base/BaseState.dart';
import '../../util/log/LogUtil.dart';


abstract class BaseController<T extends BaseState> extends GetxController{



  T initState();

  late T state;

  @override
  void onInit() {
    super.onInit();
    state = initState();
    state.init();
  }


  @mustCallSuper
  Future<void> close() async {
    _hasClosed = true;
    state.close();
  }

  bool _hasClosed = false;
  @override
  void onClose() async{
    LogUtil.println("$runtimeType hasClosed $_hasClosed");
    if(!_hasClosed){
      await close();
    }
    super.onClose();
  }
}